<?php
namespace jy_pingdd_pin;
defined('BY_JYA') or exit('error');
/*
	任务
*/
class task extends \plugin{
	/*
		团UP
	*/
	public function teamup(){
		$pluginset=$this->plugin_setting('basic');
		$params=array('plugin_name'=>'jy_pingdd_pin','status'=>0);
		$team = pdo_getall('jy_weishop_groups_team',$params,array('id','uniacid','goodsid','createtime'));
		if($team){
			foreach($team as $a){
				$_SESSION['uniacid']=$a['uniacid'];
				$goods=pdo_get('jy_weishop_goods',array('uniacid'=>$_SESSION['uniacid'],'id'=>$a['goodsid']));
				$goods=$this->model('model')->up_price($goods,$pluginset,true);
				if(time()>$goods['grouptime']*60*60+$a['createtime']){
					if($pluginset['zd_team']==1){
						$this->model('model')->order_success($a['id']);
					}else{
						$this->model('model')->order_cancel($a['id']);
					}
				}				
			}
		}
	}
	/*
		自动开团
	*/
	public function openteam(){
		return false;
		$params=array('uniacid'=>$_SESSION['uniacid'],'status'=>1);
		$goods = pdo_getall('jy_pingdd_pin_goods',$params);
		if($goods){
			foreach($goods as $item){
				$this->model('order')->openteam($item);	
			}
		}
		return false;
	}
	/*
		自动参与
	*/
	public function add_ping(){
		$pluginset=$this->plugin_setting('basic');
		$params=array();
		$yuyues = pdo_getall('jy_pingdd_pin_yuyue',$params);
		if($yuyues){
			foreach($yuyues as $yv){
				$pinggoods=pdo_get('jy_pingdd_pin_goods',array('id'=>$yv['pingid']));
				$canping=$this->model('model')->get_times($pinggoods['timeids'],'',true);
				if($canping){
					$_SESSION['uniacid']=$pinggoods['uniacid'];
					$this->model('order')->create($pinggoods,$yv);
				}				
			}
		}
	}
}